package GreedyAlgorithmPackage;

import org.junit.jupiter.api.Test;

import java.util.*;

/**
 * @author Lzm
 * @version 1.0
 */
/*先考虑一个维度, 先按身高从高向低排
* 之后按k将每个小数组插入到对应的k位置上*/
public class reconstructQueue_ {
  @Test
  public void reconstructQueueTest(){
    int[][] people = new int[][]{{7,0},{4,4},{7,1},{5,0},{6,1},{5,2}};
  }

  public int[][] reconstructQueue(int[][] people) {
    Arrays.sort(people, new Comparator<int[]>() {
      @Override
      public int compare(int[] o1, int[] o2) {
        if (o1[0] != o2[0]){
          return o2[0] - o1[0];
        }
        if (o1[0] == o2[0]){
          return o2[1] - o2[1];
        }
        return 0;
      }
    });
    //利用集合将元素插入到指定位置
    LinkedList<int[]> list = new LinkedList<>();
    for (int[] person : people) {
      //将元素person插入到指定位置
      list.add(person[1],person);
    }
    /*将集合转为二维数组*/
    System.out.println(list);
    return list.toArray(new int[people.length][]);
  }
}
